package com.zzyl.serve.controller;

import java.util.List;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.dto.NursingTaskDto;
import com.zzyl.serve.dto.TaskDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.NursingTask;
import com.zzyl.serve.service.INursingTaskService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理任务Controller
 *
 * @author quicklylearn
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务相关接口")
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 2.2.1 查询护理任务列表
     *
     * @param nursingTaskDto 护理任务查询条件
     * @return 封装分页结果
     */
   // @PreAuthorize("@ss.hasPermi('nursing:nursingTask:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo<List<NursingTask>> list(NursingTaskDto nursingTaskDto) {
        return nursingTaskService.selectNursingTaskList(nursingTaskDto);
    }

    /**
     * 2.2.2 获取护理任务详细信息
     *
     * @param id 护理任务ID
     * @return 护理任务详细信息
     */
   // @PreAuthorize("@ss.hasPermi('nursing:nursingTask:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTask> getInfo(@ApiParam(value = "护理任务ID", required = true)
                                  @PathVariable("id") Long id) {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

    /**
     * 2.2.3 取消任务
     *
     * @param taskDto 护理任务实体
     * @return 取消结果
     */
   // @PreAuthorize("@ss.hasPermi('nursing:nursingTask:cancel')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel")
    @ApiOperation("取消任务")
    public AjaxResult cancel(@ApiParam(value = "护理任务实体", required = true) @RequestBody TaskDto taskDto) {
        return toAjax(nursingTaskService.cancelTask(taskDto));
    }

    /**
     * 2.2.4 任务执行
     *
     * @param taskDto 护理任务实体
     * @return 任务执行结果
     */
    //@PreAuthorize("@ss.hasPermi('nursing:nursingTask:execute')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/do")
    @ApiOperation("任务执行")
    public AjaxResult execute(@ApiParam(value = "护理任务实体", required = true) @RequestBody TaskDto taskDto) {
        return toAjax(nursingTaskService.executeTask(taskDto));
    }

    /**
     * 2.2.5 任务改期
     *
     * @param taskDto 护理任务实体
     * @return 改期结果
     */
    //@PreAuthorize("@ss.hasPermi('nursing:nursingTask:reschedule')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping("/updateTime")
    @ApiOperation("任务改期")
    public AjaxResult reschedule(@ApiParam(value = "护理任务实体", required = true) @RequestBody TaskDto taskDto) {
        return toAjax(nursingTaskService.rescheduleTask(taskDto));
    }
}
